package com.example.aicooking.mapper;

import com.example.aicooking.entity.RefrigeratorFood;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RefrigeratorFoodMapper {
    @Select("SELECT * FROM refrigerator_foods WHERE user_id = #{userId} ORDER BY storage_time DESC")
    List<RefrigeratorFood> selectByUserId(@Param("userId") Long userId);

    @Delete("DELETE FROM refrigerator_foods WHERE id = #{id} AND user_id = #{userId}")
    int deleteByIdAndUserId(@Param("id") Long id, @Param("userId") Long userId);


    @Select("SELECT * FROM refrigerator_foods WHERE id = #{id} AND user_id = #{userId}")
    RefrigeratorFood selectByIdAndUserId(@Param("id") Long id, @Param("userId") Long userId);

}
